package cate.game.play.skill.active;

import cate.common.util.XT;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;

import java.util.List;

/**
 * 第二段伤害时，若目标生命值低于30%，则直接斩杀，不超过自身攻击力5倍/n第2回合释放，冷却4回合
 *
 * 强化效果：若目标被斩杀，随机对2个敌方目标施加【恐惧】状态，1回合内无法行动，2回合内受到的伤害提高15%，不可驱散
 */
public class 血性穿刺AH extends ActiveHandler{

	private int 血量;

	private double 攻击力系数;

	private List<Integer> 恐惧buff;

	private int buff人数;

	//血量=3000&攻击力系数=50000&
	// 恐惧buff=？？&buff人数=2
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		攻击力系数 = args.getWDouble("攻击力系数", 0d);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		恐惧buff = XT.merge(恐惧buff, args.getIntList("恐惧buff"));
		buff人数 += args.getInt("buff人数", 0);
	}

	@Override
	public void beforeSingleEffect(SkillActionCtx action, SkillEffect effect, Fighter target) {
		if (target.attr.hpCur() > skill.owner.attr.attTotal() * 攻击力系数) {
			return;
		}
		if (target.attr.total().hpCurRate() > 血量) {
			return;
		}
		target.attr.kill(action, skill.owner);
		if (XT.isNotBlank(恐惧buff) && buff人数 > 0) {
			TargetFilterParam param = new TargetFilterParam().targetNumSet(buff人数);
			for (Fighter fighter : TargetSelector.doFind(skill.owner, action.getTeamVs(), param)) {
				for (Integer integer : 恐惧buff) {
					fighter.buff.tryAddByTid(action, skill.owner, integer);
				}
			}
		}
	}
}
